package com.googlecode.nacl_optimizer.elf.headers;

import java.util.Arrays;

import com.googlecode.nacl_optimizer.elf.types.Elf32Addr;
import com.googlecode.nacl_optimizer.elf.types.Elf32Off;
import com.googlecode.nacl_optimizer.elf.types.Elf32Word;

public class SectionHeader {
    private Elf32Word name;
    private SectionTypeField type;
    private Elf32Word flags;
    private Elf32Addr addr;
    private Elf32Off offset;
    private Elf32Word size;
    private Elf32Word link;
    private Elf32Word info;
    private Elf32Word addralign;
    private Elf32Word entsize;

    public SectionHeader(byte[] data, DataEncoding enc) {
        name = new Elf32Word(enc, data);
        data = Arrays.copyOfRange(data, 4, data.length);
        type = SectionTypeField.getType(new Elf32Word(enc, data));
        data = Arrays.copyOfRange(data, 4, data.length);
        flags = new Elf32Word(enc, data);
        data = Arrays.copyOfRange(data, 4, data.length);
        addr = new Elf32Addr(enc, data);
        data = Arrays.copyOfRange(data, 4, data.length);
        offset = new Elf32Off(enc, data);
        data = Arrays.copyOfRange(data, 4, data.length);
        size = new Elf32Word(enc, data);
        data = Arrays.copyOfRange(data, 4, data.length);
        link = new Elf32Word(enc, data);
        data = Arrays.copyOfRange(data, 4, data.length);
        info = new Elf32Word(enc, data);
        data = Arrays.copyOfRange(data, 4, data.length);
        addralign = new Elf32Word(enc, data);
        data = Arrays.copyOfRange(data, 4, data.length);
        entsize = new Elf32Word(enc, data);
    }

    public SectionTypeField getType() {
        return type;
    }

    public Elf32Word getName() {
        return name;
    }
}
